﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Office.OneNote;
using System.IO;
using System.Globalization;
using NUnit.Framework;

namespace OneNoteFrameworkTests
{
    [TestFixture]
    public sealed class NotebookTests : HierarchyTestBase
    {
        [Test]
        public void ChangeNotebookColor()
        {
            RunNotebookTest(notebook =>
            {
                notebook.Color = OneNoteColor.Cyan;
                
                notebook.SubmitChanges();
                notebook.Update();

                Assert.AreEqual(OneNoteColor.Cyan, notebook.Color);
            });
        }

        [Test]
        public void CreatePage()
        {
            RunSectionTest(section =>
            {
                OneNotePage page = section.CreatePage();
                Assert.IsNotNull(page);
                Assert.AreEqual(page, section.Pages[0]);
                Assert.IsTrue(section.Delete(page));
            });
        }

        [Test]
        public void CreatePageAndModifyContent()
        {
            RunPageTest(page =>
            {
                CultureInfo language = page.Language;
                Assert.IsNull(language);

                page.Language = CultureInfo.CurrentCulture;
                page.SubmitChanges();

                Assert.AreEqual(CultureInfo.CurrentCulture, page.Language);
            });
        }

        [Test]
        public void CreateSectionAndGroup()
        {
            RunNotebookTest(notebook =>
            {
                const string GroupName = "TestGroup";
                const string SectionName = "TestSection";

                OneNoteSectionGroup group = notebook.OpenSectionGroup(GroupName);
                Assert.IsNotNull(group);
                Assert.AreEqual(GroupName, group.Name);
                Assert.AreEqual(Path.Combine(notebook.Path, GroupName), group.Path);
                Assert.AreEqual(0, group.Pages.Count);
                Assert.AreEqual(0, group.Sections.Count);

                OneNoteSection section = group.OpenSection(SectionName);
                Assert.IsNotNull(section);
                Assert.AreEqual(SectionName, section.Name);
                Assert.AreEqual(Path.Combine(group.Path, SectionName + ".one"), section.Path);
                Assert.AreEqual(0, section.Pages.Count);

                Assert.IsTrue(group.Delete(section));
                Assert.IsTrue(notebook.Delete(group));
            });
        }
    }
}
